(function(){
  'use strict';

  var config = require('./config'),
      express = require('express'),
      morgan = require('morgan'),
      compress = require('compression'),
      bodyParser = require('body-parser'),
      methodOverride = require('method-override');

  module.exports = function(){
    var app = express();

    if(process.env.NODE_ENV === 'development'){
      app.use(morgan('dev'));
    } else if(process.env.NODE_ENV === 'production'){
      app.use(compress());
    }

    app.set('port', process.env.PORT | config.port | 3000);

    app.use(bodyParser.urlencoded({
      extended: true
    }));
    app.use(bodyParser.json());
    app.use(methodOverride());

    app.use(express.static('./public'));

    return app;
  };
}());
